package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.db.UserInfo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    /**
     * 查询用户列表
     * */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize){
      PageResult vo = manageService.users(page,pagesize);
      return ResponseEntity.ok(vo);
    }
    /**
     * 查询用户详情
     * */
    @GetMapping("/users/{userId}")
    public ResponseEntity findUserById(@PathVariable("userId") Long userId){
      UserInfo userInfo =  manageService.findUserById(userId);
        return ResponseEntity.ok(userInfo);
    }
    /**
     * 查询视频列表
     * */
    @GetMapping("/videos")
    public ResponseEntity findVideos(@RequestParam(defaultValue = "1")Integer page,
                                     @RequestParam(defaultValue = "10")Integer pagesize,
                                     Long uid){
       PageResult vo = manageService.findVideos(page,pagesize,uid);
       return ResponseEntity.ok(vo);
    }
    /**
     * 查询动态列表
     * */
    @GetMapping("/messages")
    public ResponseEntity findMovements(@RequestParam(defaultValue = "1")Integer page,
                                        @RequestParam(defaultValue = "10")Integer pagesize,
                                        Long uid,String state){
        //处理异常   忽略
        Integer status= null;
        if (StringUtils.isNotEmpty(state)&& !"''".equals(state)){
            status = Integer.valueOf(state);
        }
        PageResult vo = manageService.findMovements(status,uid,page,pagesize);
        return ResponseEntity.ok(vo);
    }
    /**
     * 根据id查询动态
     * */
    @GetMapping("/messages/{id}")
    public ResponseEntity findMovementById(@PathVariable("id")String id){
        MovementsVo vo = manageService.findMovementById(id);
        return ResponseEntity.ok(vo);
    }
    /**
     * 根据动态id查询评论
     */

    @GetMapping("/messages/comments")
    public ResponseEntity findCommentsById(@RequestParam(defaultValue = "1")Integer page,
                                           @RequestParam(defaultValue = "10")Integer pagesize,
                                           String messageID){
       PageResult result = manageService.findCommentsById(page,pagesize,messageID);
       return ResponseEntity.ok(result);
    }
}
